<html>
<head>
  <title></title>
  <meta charset="utf-8">
  <script type="text/javascript" src="ajax.js"></script>
</head>
<body>
用户名：<input type="text" id="user"><br/>
密码：<input type="password" id="pass"></input><br/>
<input type="button" value="注册" id="reg_btn"/>
<input type="button" value="登录" id="login_btn"/>

<!-- 自己的js -->
<script type="text/javascript">
  //获取元素
  var user=document.getElementById('user');
  var pass=document.getElementById('pass');
  var oBtnReg=document.getElementById('reg_btn');
  var oBtnLogin=document.getElementById('login_btn');

  //注册
  oBtnReg.onclick=function () {
    ajax({
      url:'/user',
      data:{act:'reg',user:user.value,pass:pass.value},
      type:'post',
      success:function (str) {
        console.log(str);
      },
      error:function () {
        console.log('通信错误');
      }
    })
  }
  oBtnLogin.onclick=function () {
    ajax({
      url:'/user',
      data:{act:'login',user:user.value,pass:pass.value},
      type:'post',
      success:function (str) {
        console.log(str);
      },
      error:function () {
        console.log('通信错误');
      }
    })
  }
</script>
</body>
</html>